package com.mobilezu.mobile.pushserver.console.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
import com.mobilezu.mobile.pushserver.model.PushUser;
import com.mobilezu.mobile.pushserver.service.PushUserService;
import com.mobilezu.mobile.pushserver.service.ServiceManager;
import com.mobilezu.mobile.pushserver.xmpp.presence.PresenceManager;



public class UserController extends MultiActionController {

	private PushUserService pushUserService;

	public UserController() {
		pushUserService = ServiceManager.getPushUserService();
	}

	public ModelAndView list(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		PresenceManager presenceManager = new PresenceManager();
		List<PushUser> userList = pushUserService.getPushUsers();
		for (PushUser user : userList) {
			if (presenceManager.isAvailable(user)) {
				// Presence presence = presenceManager.getPresence(user);
				user.setOnline(true);
			} else {
				user.setOnline(false);
			}
			// logger.debug("user.online=" + user.isOnline());
		}
		ModelAndView mav = new ModelAndView();
		mav.addObject("userList", userList);
		mav.setViewName("user/user_list");
		return mav;
	}

}
